<?php


namespace app\applet\middleware;


use app\lib\util\JwtUtils;
use think\facade\Db;

class CheckBouseHouse
{
    public function handle($request, \Closure $next)
    {
        $accessToken=request()->header("accessToken");
        if(empty($accessToken)){
            return json(["code"=>403,'msg' => "用户未登录"]);
        }
        $userResult=JwtUtils::getDecodeToken($accessToken);
        $request->accessToken=  $accessToken;
        $request->openid=  $userResult["openid"];
        //查询用户有没有绑定房屋
        $userRoomList=Db::table("wxpro_roominfo_user")->where("openid",$userResult["openid"])->select();
        if(empty($userRoomList)){
            return json(["code"=>10021,'msg' => "用户未绑定房屋"]);
        }
        $request->userRoomList=  $userRoomList;
        return $next($request);  //返回request闭包 固定格式写到这里
    }
}